﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using Mars.EnCor.Properties;

namespace Mars.EnCor.Config
{
    public class ModuleConfig : NameTypeConfigElement
    {
        private const string Config_Services = "services";
        private const string DefaultModuleType = "Mars.EnCor.Module, Mars.EnCor";
        private const string Config_Type = "type";
        private const string Config_DataType = "dataType";
        private const string DefaultModuleDataType = "Mars.EnCor.Config.ModuleConfig, Mars.EnCor";

        [ConfigurationProperty(Config_Services)]
        public ServiceConfigCollection Services
        {
            get
            {
                return (ServiceConfigCollection)this[Config_Services];
            }
        }
        
        [ConfigurationProperty(Config_Type, DefaultValue= DefaultModuleType)]
        public override string TypeName
        {
            get
            {
                return (string)this[Config_Type];
            }
        }

        [ConfigurationProperty(Config_DataType, DefaultValue = DefaultModuleDataType)]
        public string DataTypeName
        {
            get
            {
                return (string)this[Config_DataType];
            }
        }

        public Type DataType
        {
            get
            {
                return Type.GetType(DataTypeName);
            }
        }

        protected override bool OnDeserializeUnrecognizedElement(string elementName, System.Xml.XmlReader reader)
        {
            return base.OnDeserializeUnrecognizedElement(elementName, reader);
        }



        public void DeserializeElement(System.Xml.XmlReader reader)
        {
            DeserializeElement(reader, false);
        }
    }
}
